home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-07-14 | 1.2 KB | 45 lines | [TEXT/MPS ] |
-
- UNIT Persist;
-
- { This is a stand-alone module which maintains a running total }
- { of the squares of the parameters it receives. This requires }
- { the cooperation of a host application. The host must use }
- { messages to tell the module when to initialize and when to }
- { tear down. The host also must maintain a handle to the }
- { module's A5 world between invocations. }
-
- INTERFACE
-
- USES
- Types, SAGlobals;
-
- CONST
- kAccumulate = 0; {These are the control messages.}
- kFirstTime = 1;
- kLastTime = 2;
-
- FUNCTION AccSquares (parm: Longint; message: Integer;
- VAR A5Ref: A5RefType) : Longint;
-
- IMPLEMENTATION
-
- { Define global storage to retain a running }
- { total over multiple calls to the module. }
- VAR accumulation : Longint;
-
- FUNCTION AccSquares (parm: Longint; message: Integer;
- VAR A5Ref: A5RefType) : Longint;
- VAR
- oldA5: Longint;
- BEGIN
- IF message = kFirstTime THEN MakeA5World(A5Ref);
- oldA5 := SetA5World(A5Ref);
- IF message = kFirstTime THEN accumulation := 0;
- accumulation := accumulation + (parm * parm);
- AccSquares := accumulation;
- RestoreA5World(oldA5, A5Ref);
- IF message = kLastTime THEN DisposeA5World(A5Ref);
- END;
-
- END.
-